# date:20210220
from typing import List
import collections

class Solution:
    def longestSubarray(self, nums: List[int], limit: int) -> int:
        left, right = 0, 0
        result = [0]
        while(right <= len(nums)):
            if left == right:
                right += 1
                continue
            if max(nums[left:right]) - min(nums[left:right]) <= limit:
                print(f'left: {left}', f'right: {right}', f'nums: {nums[left: right]}')
                result.append(right-left)
                right += 1
            else:
                left += 1
        return max(result)




model = Solution()

# nums = [8,2,4,7]
# limit = 4
# print(model.longestSubarray(nums, limit))

nums = [10,1,2,4,7,2]
limit = 5
print(model.longestSubarray(nums, limit))

# nums = [4,2,2,2,4,4,2,2]
# limit = 0
# print(model.longestSubarray(nums, limit))